unit UntUserDB;

interface

uses
  UntUser;

type
  TUserDB = class(TObject)
  private
    const PWD_ADD :string = 'pwd';
  public
    class function getUser(userName, password: string): TUser;
    class function updatePwd(userName, password: string): Boolean;
  end;

implementation

uses
  UntDMDB;

class function TUserDB.getUser(userName, password: string): TUser;
var user:TUser;
begin
  user := nil;
  with DMMySQL.myqryCom do
  begin
    Close;
    SQL.Text := 'select * from sys_user where userName=:PUserName and password=md5(:PPassword) and active=1 ';
    ParamByName('PUserName').AsString := userName;
    ParamByName('PPassword').AsString := password+PWD_ADD;
    Open;
    try
      First;
      if not Eof then
      begin
        user:=TUser.Create();
        user.Role := FieldByName('role').AsInteger;
        user.name := FieldByName('userName').AsString;
      end;
    finally
      Close;
    end;
  end;
  Result := user  ;
end;

class function TUserDB.updatePwd(userName, password: string): Boolean;
begin
  with DMMySQL.myqryCom do
  begin
    Close;
    SQL.Text := 'update  sys_user set password=md5(:PPassword) where userName=:PUserName and active=1 ';
    ParamByName('PUserName').AsString := userName;
    ParamByName('PPassword').AsString := password+PWD_ADD;
    ExecSQL;
  end;
  Result := True;  ;
end;

end.
